package mergestring

import (
	"fmt"
	"log"
	"os"
)

func (m *MergeString) Merge() string {

	ws := make([]byte, 0, len(m.Word1)+len(m.Word2))
	for i := 0; i < len(m.Word2) || i < len(m.Word1); i++ {
		if len(m.Word1) > i {
			ws = append(ws, m.Word1[i])
		}
		if len(m.Word2) > i {
			ws = append(ws, m.Word2[i])
		}
	}
	return string(ws)
}

func (m *MergeString) LogToFile(s string) {
	filePath, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	file, err := os.OpenFile(fmt.Sprintf("%s/%v", filePath, "file.log"), os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	l := log.New(file, "Info: ", log.LstdFlags|log.Lmsgprefix)
	l.Println(s)
}

func (lg *Log) LogToFile(s string) {
	filePath, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	file, err := os.OpenFile(fmt.Sprintf("%s/%v", filePath, "file.log"), os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	l := log.New(file, lg.L, log.LstdFlags|log.Lmsgprefix)
	l.Println(s)
}
